package wt.hpad.model.remote.customParseJson;

import wt.hpad.model.bean.Dish;
import wt.hpad.model.bean.DishDetail;
import wt.hpad.model.bean.DishType;
import wt.hpad.model.bean.ResponseMessage;
import wt.hpad.model.bean.TableInfo;
import wt.hpad.utils.GsonUtil;

import static wt.hpad.ConstantFields.MSG_ADD;
import static wt.hpad.ConstantFields.MSG_LOGIN;
import static wt.hpad.ConstantFields.MSG_MENU;
import static wt.hpad.ConstantFields.MSG_RETURN;
import static wt.hpad.ConstantFields.MSG_TABLE;
import static wt.hpad.ConstantFields.MSG_TABLE_ONE;
import static wt.hpad.ConstantFields.MSG_TYPE;
import static wt.hpad.ConstantFields.MSG_UNTABLE;
import static wt.hpad.utils.LogUtil.logI;

/**
 * 解析"所有未上菜"消息
 * Created by wt on 10.26.
 */

public class ParseMessage extends BaseResponseConverter<ResponseMessage> {
    private static final String TAG = "ParseMessage";


    @Override
    public ResponseMessage parserJson(String jsonString) {
        logI("ParseMessage", "parserJson |  ", "" + jsonString);
        ResponseMessage message = GsonUtil.jsonToBean(jsonString, ResponseMessage.class);

        String msgType = message.msgType;
        logI(TAG, "parserJson |  ", "" + msgType);

        if (msgType != null) {
            switch (msgType) {
                case MSG_TABLE:
                    message = GsonUtil.toBeanWithGenericity(jsonString, ResponseMessage.class, TableInfo.class);
                    break;
                case MSG_MENU:
                    message = GsonUtil.toBeanWithGenericity(jsonString, ResponseMessage.class, Dish.class);
                    break;
                case MSG_UNTABLE:    // 未开台
                case MSG_TABLE_ONE:  // 已开台
                    message = GsonUtil.toBeanWithGenericity(jsonString, ResponseMessage.class, DishDetail.class);
                    break;
                case MSG_TYPE:  // 菜品分类
                    message = GsonUtil.toBeanWithGenericity(jsonString, ResponseMessage.class, DishType.class);
                case MSG_RETURN:   // 退菜
                case MSG_ADD:      // 点菜
                case MSG_LOGIN:    // 登录
                    break;
            }
        }
        return message;
    }
}
